﻿

using Admin.NET.Core.Btms;
using Minio.DataModel;

namespace Admin.NET.Application.Service;
//状态模式
public interface ITraBiaoBenStateManager
{
    Task<string> BangDing(TraBiaoBenSaoMaInput input);// 绑定  
    string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity);// 采集  
    string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity);// 送出  
    string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity); // 送达
    string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity);//  接收
    string XiaoHui(TraBiaoBenSaoMaInput input, TraBiaoBen entity);//销毁
    string ZuoFei(TraBiaoBenSaoMaInput input, TraBiaoBen entity);//作废
}
//绑定  采集 送出 送达 接收 销毁 作废
public class TraGongGongStateManager : ITraBiaoBenStateManager
{

    protected readonly SqlSugarRepository<TraBiaoBen> _rep;
    public TraGongGongStateManager(SqlSugarRepository<TraBiaoBen> rep)
    {
        _rep = rep;
    }

    //绑定申请单
    public virtual async Task<string> BangDing(TraBiaoBenSaoMaInput input)
    {

        await _rep.InsertAsync(new TraBiaoBen
        {
            Id = input.Id,
            biaoBenLeiXing = input.biaoBenLeiXing,
            traShenQingId = input.traShenQingId,
            huanZheId = input.huanZheId,
            danJuZhuangTai = BiaoBenZhuangTai.已绑定,
            bangDingRenId = input.caoZuoRenId,
            bangDingShiJian = input.caoZuoShiJian,
            bangDingKeShiId = input.caoZuoKeShiId,
        });

        // int value = StatusHelper<BiaoBenZhuangTai>.GetStatusValue(BiaoBenZhuangTai.已绑定); // 返回1

        return "绑定";
    }

    //采集   没其他逻辑
    public virtual string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {
        entity.caiJiRenId = input.caoZuoRenId;
        entity.caiJiHeDuiRenId = input.caoZuoHeDuiRenId;
        entity.caiJiKeShiId = input.caoZuoKeShiId;
        entity.caiJiShiJian = input.caoZuoShiJian;
        entity.danJuZhuangTai = BiaoBenZhuangTai.已采集;
        _rep.Update(entity);

        //采集收费

        return "采集";
    }
    //送出    没其他逻辑 
    public virtual string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {
        entity.songChuRenId = input.caoZuoRenId;
        entity.songChuKeShiId = input.caoZuoKeShiId;
        entity.songChuShiJian = input.caoZuoShiJian;
        entity.danJuZhuangTai = BiaoBenZhuangTai.已送出;
        _rep.Update(entity);
        return "送出";

    }
    //送达
    public virtual string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {
        entity.songDaRenId = input.caoZuoRenId;
        entity.songDaShiJian = input.caoZuoShiJian;
        entity.danJuZhuangTai = BiaoBenZhuangTai.已送达;
        _rep.Update(entity);
        return "送达";
    }
    //接收
    public virtual string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {
        entity.jieShouRenId = input.caoZuoRenId;
        entity.jieShouShiJian = input.caoZuoShiJian;
        entity.jieShouKeShiId = input.caoZuoKeShiId;
        entity.danJuZhuangTai = BiaoBenZhuangTai.已接收;
        _rep.Update(entity);
        return "接收";
    }
    //销毁
    public virtual string XiaoHui(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {

        entity.xiaoHuiRenId = input.caoZuoRenId;
        entity.xiaoHuiShiJian = input.caoZuoShiJian;
        entity.danJuZhuangTai = BiaoBenZhuangTai.已销毁;
        _rep.Update(entity);
        return "销毁";
    }
    //作废
    public virtual string ZuoFei(TraBiaoBenSaoMaInput input, TraBiaoBen entity)
    {

        entity.zuoFeiRenId = input.caoZuoRenId;
        entity.zuoFeiRenShiJian = input.caoZuoShiJian;
        _rep.Update(entity);

        return "作废";
    }
}



//待绑定状态  --只能绑定
public class TraDaiBangDingStateManager : TraGongGongStateManager
{

    public TraDaiBangDingStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }

    public string stateMessage = "待绑定";

    public override string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("采集失败,标本处于" + stateMessage + "状态,无法采集"); }
    public override string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送出失败,标本处于" + stateMessage + "状态,无法送出"); }

    public override string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送达失败,标本处于" + stateMessage + "状态,无法送达"); }

    public override string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("接收失败,标本处于" + stateMessage + "状态,无法接收"); }

    public override string XiaoHui(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("销毁失败,标本处于" + stateMessage + "状态,无法销毁"); }

    public override string ZuoFei(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("作废失败,标本处于" + stateMessage + "状态,无法作废"); }
}

//绑定状态   --只能采集、 销毁、作废
public class TraBangDingStateManager : TraGongGongStateManager
{

    public TraBangDingStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }

    public string stateMessage = "绑定";

    public override async Task<string> BangDing(TraBiaoBenSaoMaInput input) { throw Oops.Oh("绑定失败,标本处于" + stateMessage + "状态,无法绑定"); }

    public override string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送出失败,标本处于" + stateMessage + "状态,无法送出"); }

    public override string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送达失败,标本处于" + stateMessage + "状态,无法送达"); }

    public override string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("接收失败,标本处于" + stateMessage + "状态,无法接收"); }

}

//采集状态 --只能重复采集、 送出、 销毁 作废
public class TraCaiJiStateManager : TraGongGongStateManager
{
    public TraCaiJiStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }

    public string stateMessage = "采集";
    public override async Task<string> BangDing(TraBiaoBenSaoMaInput input) { throw Oops.Oh("绑定失败,标本处于" + stateMessage + "状态,无法绑定"); }

    public override string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送达失败,标本处于" + stateMessage + "状态,无法送达"); }

    public override string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("接收失败,标本处于" + stateMessage + "状态,无法接收"); }


}

//送出状态   --只能重复 送出、送达、销毁 作废
public class TraSongChuStateManager : TraGongGongStateManager
{
    public TraSongChuStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }
    public string stateMessage = "送出";
    public override async Task<string> BangDing(TraBiaoBenSaoMaInput input) { throw Oops.Oh("绑定失败,标本处于" + stateMessage + "状态,无法绑定"); }
    public override string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("采集失败,标本处于" + stateMessage + "状态,无法采集"); }

    public override string JieShou(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("接收失败,标本处于" + stateMessage + "状态,无法接收"); }
}


//送达状态  --只能重复 送达、接收、销毁 作废
public class TraSongDaStateManager : TraGongGongStateManager
{
    public TraSongDaStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }


    public string stateMessage = "送达";

    public override async Task<string> BangDing(TraBiaoBenSaoMaInput input) { throw Oops.Oh("绑定失败,标本处于" + stateMessage + "状态,无法绑定"); }

    public override string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("采集失败,标本处于" + stateMessage + "状态,无法采集"); }
    public override string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送出失败,标本处于" + stateMessage + "状态,无法送出"); }

}

//接收状态  --只能重复 接收、销毁 作废
public class TraJieShouStateManager : TraGongGongStateManager
{

    public string stateMessage = "接收";
    public TraJieShouStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {
    }
    public override async Task<string> BangDing(TraBiaoBenSaoMaInput input) { throw Oops.Oh("绑定失败,标本处于" + stateMessage + "状态,无法绑定"); }

    public override string CaiJi(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("采集失败,标本处于" + stateMessage + "状态,无法采集"); }
    public override string SongChu(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送出失败,标本处于" + stateMessage + "状态,无法送出"); }

    public override string SongDa(TraBiaoBenSaoMaInput input, TraBiaoBen entity) { throw Oops.Oh("送达失败,标本处于" + stateMessage + "状态,无法送达"); }

}

//标本作废

public class TraZuoFeiStateManager : TraGongGongStateManager
{
    public TraZuoFeiStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }
}

//标本销毁
public class TraXiaoHuiStateManager : TraGongGongStateManager
{
    public TraXiaoHuiStateManager(SqlSugarRepository<TraBiaoBen> rep) : base(rep)
    {

    }
}
